package com.chucang.shucang.sys.controller;

import cn.hutool.core.text.CharSequenceUtil;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.chucang.shucang.common.base.utils.R;
import com.chucang.shucang.common.security.annotation.Inner;
import com.chucang.shucang.sys.entity.OauthClientDetailsEntity;
import com.chucang.shucang.sys.exception.SysErrorCode;
import com.chucang.shucang.sys.service.OauthClientDetailsService;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 终端信息表
 *
 * @author flitsneak flitsneak@gmail.com
 * @since 1.0.0 2022-09-16
 */
@RestController
@RequestMapping("/oauthclientdetails")
@RequiredArgsConstructor
@Api(tags = "终端信息表")
public class OauthClientDetailsController {

    private final OauthClientDetailsService oauthClientDetailsService;

    /**
     * 获取客户端信息
     *
     * @param clientId 客户端id
     * @return 客户端信息
     */
    @Inner
    @GetMapping("getClientDetailsById/{clientId}")
    public R<OauthClientDetailsEntity> getClientDetailsById(@PathVariable String clientId) {
        if (CharSequenceUtil.isBlank(clientId)) {
            return R.failed(SysErrorCode.CLIENT_NULL_EXCEPTION.getCode(), SysErrorCode.CLIENT_NULL_EXCEPTION.getMsg());
        }
        OauthClientDetailsEntity oauthClientDetails = new LambdaQueryChainWrapper<>(oauthClientDetailsService.getBaseMapper())
                .eq(OauthClientDetailsEntity::getClientId, clientId)
                .select()
                .one();
        return R.ok(oauthClientDetails);
    }
}